package com.yingxin.yxerp.module.sys.service.impl;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yingxin.yx.framework.commons.enums.BusinessType;
import com.yingxin.yxerp.module.oplog.aop.OplogAnnotation;
import com.yingxin.yxerp.module.sys.entity.Company;
import com.yingxin.yxerp.module.sys.mapper.CompanyMapper;
import com.yingxin.yxerp.module.sys.service.ICompanyService;
import com.yingxin.yxerp.module.sys.vo.resp.CompanyRespVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 分公司 服务实现类
 * @author fanchao
 * @since 2022-01-08
 */

@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements ICompanyService {


    @OplogAnnotation(biz = BusinessType.COMPANY_SETTING, id = "{{company.id}}", action = "关联客户",
            desc = "厂区{{company.name}}，关联客户{{company.merchantId}}")
    @Transactional(rollbackFor = RuntimeException.class)
    @Override
    public void updateMerchantId(Company company) {
        UpdateWrapper<Company> uw = new UpdateWrapper<>();
        uw.lambda().set(Company::getMerchantId, company.getMerchantId());
        uw.lambda().eq(Company::getId, company.getId());
        update(uw);
    }

    @Override
    public CompanyRespVo getVo(String id){
        return baseMapper.getVo(id);
    }
}
